package com.idlecode.statics;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: IdleCode
 * @description 支持的日期格式
 * @author: rongjuwei
 * @create: 2024-07-11 08:36
 **/
public class CodeFormat {
    private final static List<String> DATE_FORMAT;

    private static final Map<String, String> CODE_FORMATS = new LinkedHashMap<>();

    static {
        DATE_FORMAT = CollUtil.newArrayList(
                "yyyy",
                "yyyy-MM",
                "yyyy-MM-dd",
                "yyyy-MM-dd HH",
                "yyyy-MM-dd HH:mm",
                "yyyy-MM-dd HH:mm:ss",
                "yyyy年",
                "yyyy年MM月",
                "yyyy年MM月dd日",
                "yyyy年MM月dd日HH时",
                "yyyy年MM月dd日HH时mm分",
                "yyyy年MM月dd日HH时mm分ss秒",
                "yyyyMM",
                "yyyyMMdd",
                "yyyyMMddHH",
                "yyyyMMddHHmm",
                "yyyyMMddHHmmss",
                "yyyy/MM",
                "yyyy/MM/dd",
                "yyyy/MM/dd HH",
                "yyyy/MM/dd HH:mm",
                "yyyy/MM/dd HH:mm:ss"
        );

        CODE_FORMATS.putAll(TemplateInfo1Util.info);
        CODE_FORMATS.putAll(TemplateInfo1_1Util.info);
        CODE_FORMATS.putAll(TemplateInfo2Util.info);
        CODE_FORMATS.putAll(TemplateInfo3Util.info);
        CODE_FORMATS.putAll(TemplateInfo4Util.info);
    }

    /**
     * 表字段描述
     */
    public static String getDateFormat(String fieldComment) {
        if (StrUtil.isBlank(fieldComment)) {
            return null;
        }
        String returnStr = "";
        for (String checkStr : CodeFormat.DATE_FORMAT) {
            if (null != checkStr && fieldComment.toString().contains(checkStr)) {
                if (checkStr.length() >= returnStr.length()) {
                    returnStr = checkStr;
                }
            }
        }
        return returnStr;
    }


    public final static Map<String, String> getCodeFormats() {
        return CODE_FORMATS;
    }
}